package com.signway.javaui.slice.component;

import com.signway.javaui.ResourceTable;
import com.signway.javaui.base.BaseAbilitySlice;
import com.signway.javaui.utils.SwLog;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Picker;

import java.util.HashMap;
import java.util.Map;

public class PickerComponent extends BaseAbilitySlice {

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_slice_component_picker);
        initView();
    }

    private void initView() {
        if (!(findComponentById(ResourceTable.Id_week_picker) instanceof Picker)) {
            SwLog.info("initView");
            terminate();
        }
        Picker weekPicker = (Picker) findComponentById(ResourceTable.Id_week_picker);

        Map<Integer, String> weekMap = new HashMap<>();
        weekMap.put(0, "周日");
        weekMap.put(1, "周一");
        weekMap.put(2, "周二");
        weekMap.put(3, "周三");
        weekMap.put(4, "周四");
        weekMap.put(5, "周五");
        weekMap.put(6, "周六");

        weekPicker.setFormatter(i -> {
            return weekMap.getOrDefault(i, "未知");
        });
    }
}
